< previous page page_367 next page >

Page 367
What you have just completed is the quickest way of executing a report from Crystal Reports. However, in most applications there is usually more than one report that the users will need to display or print, so you will need to change the Crystal Reports control's properties at runtime. Otherwise, you would need to place a separate report control for each report you supply to the user. All the major properties of the Crystal Reports control, such as ReportFileName and SelectionFormula, are available at runtime. The following example code sets up the Crystal Reports control for a new report and specifies a selection criteria based on user input:
crReport.ReportFileName = AddrList.rpt
crReport.SelectionFormula = {EntryList.State}= & txtStateCd
crReport.action = crRunReport  This is a constant for the value 1
The other property that you may need to set at runtime is the DataFiles property. This property is not available at designtime. It specifies the name of the database file that is used by the report. Unless the user installs your application in exactly the same directory that you have on your computer, you will need to tell the Crystal Reports control the location of the database file on the users PC.
The DataFiles property is actually an array with the first element number of zero. If you're using more than one database in your report, you need to set the value of each DataFiles array element for each database. For most of your reports, however, you will be using only a single database. The following line of code shows you how to set the value of the DataFiles property for the database. This line assumes that the database file is in the same folder as your application:
crReport.DataFiles(0) = App.Path & \AddressBook.mdb
Creating a User Interface
In complex Visual Basic applications, you really need to give the user a good interface to select and modify the options when running reports. In an application that I developed, a Visual Basic form was used with several controls in conjunction with an input table to create the report manager shown in Figure 13.22.
This particular report manager displays report descriptions in a Tree View control with headings for each group of reports that is added to the list. It also makes use of the Common Dialog control to display the Printer dialog box. Using a Tree View control requires copious amounts of code to populate and control it. Instead you could create a simpler version of this interface, replacing the TreeView control with a ListBox control, as shown in Figure 13.23.

 
< previous page page_367 next page >

If you like this book, buy it!